package deposit.main;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class Main {

    public static void main(String[] args) {

	@SuppressWarnings("deprecation")
	Date date = new Date(2012, 8, 8);

	Deposit sd1 = new SimpleDeposit("PRIVAT", "1", date, 20, 1000, 15.0);
	Deposit mcd1 = new MonthCapitalizeDeposit("PRIVAT", "2", date, 20,
		2500, 18.0);

	Deposit sd2 = new SimpleDeposit("PRIVAT", "3", date, 40, 10000, 11.5);
	Deposit mcd2 = new MonthCapitalizeDeposit("PRIVAT", "4", date, 80,
		5000, 14.0);

	List<Deposit> deposits = new ArrayList<Deposit>();
	deposits.add(sd1);
	deposits.add(sd2);
	deposits.add(mcd1);
	deposits.add(mcd2);

	double sum = 0.0;
	for (Deposit d : deposits) {
	    sum += d.getInterest();
	}

	System.out.printf("%.2f\n", sum);

	InterestInterface[] depsitesInter = new InterestInterface[4];

	depsitesInter[0] = new SimpleDeposit("PRIVAT", "1", date, 20, 1000,
		15.0);
	depsitesInter[1] = new MonthCapitalizeDeposit("PRIVAT", "2", date, 20,
		2500, 18.0);
	depsitesInter[2] = new SimpleDeposit("PRIVAT", "3", date, 40, 10000,
		11.5);
	depsitesInter[3] = new MonthCapitalizeDeposit("PRIVAT", "4", date, 80,
		5000, 14.0);

	// double sum2 = 0.0;
	// for (InterestInterface d : depsitesInter) {
	// sum2 += d.getInterest();
	// }
	//
	// System.out.printf("%.2f", sum2);
	//

	// ListDeposits ld = new ListDeposits();
	// ld.init();
	// System.out.printf("\n%.2f", ld.getPrincipal());
	// ld.remove();
	// System.out.printf("\n%.2f", ld.getPrincipal());
	//
	//
	// ld.printSortedSumAndInterest(deposits);
	//
	// ld.writeSortedSumAndInterest(deposits, "C:\\11111111.txt");
	//
	// ld.saveDeposits(deposits,"C:\\111.txt");
	// System.out.println("\n------------------------------------------------------");
	// ld.printSortedSumAndInterest(ld.readObject("C:\\111.txt"));

	ThreadTest ttest = new ThreadTest();
	Thread t1 = new Thread(ttest);
	Thread t2 = new Thread(ttest);
	ListDeposits list = new ListDeposits();

	list.init();
	ttest.setListDeposits(list);
	ttest.setIndex(2);
	System.out.println(ttest.getSum());

	t1.start();
	t2.start();
	try {
	    t1.join();
	    t2.join();
	} catch (Throwable ex) {
	    ex.printStackTrace();
	}
	System.out.println(ttest.getSum());

    }
}
